<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\FourDoctor;
use App\Models\Campu;
use App\Models\FourAdminTitle;
use App\Models\FourCampus;
use App\Models\FourDepartment;
use App\Models\FourLabel;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;


class FourDoctorController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(FourDoctor::with(['campus','title','department','label']), function (Grid $grid) {
            $grid->title('医生管理');
            $grid->column('id')->sortable();
            $grid->column('name','医生姓名')->setHeaderAttributes(['style' => 'color:#5b69bc']);
            $grid->column('avatar','头像')->image([],80,80);
            $grid->column('campus.campus_name','院区')->help('提示信息');
            $grid->column('title.title','职称');
            $grid->column('department.name','科室');
            $grid->column('label.label_name','标签')->label('danger');
            $grid->column('desc','描述');
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();
            //导出
            $grid->export()->xlsx()->filename('医生信息');
            //查询过滤
            $grid->filter(function (Grid\Filter $filter) {
                // 更改为 panel 布局
                $filter->panel();

                // 注意切换为panel布局方式时需要重新调整表单字段的宽度
                $filter->between('created_at','创建时间')->toTimestamp();
                $filter->like('name','医生姓名')->width(3);

            });
            // 开启字段选择器功能
            $grid->showColumnSelector();
            // 设置表单提示值
            $grid->quickSearch('name')->placeholder('搜索...');
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new FourDoctor(), function (Show $show) {
            $show->field('name','医生姓名');
            $show->avatar('头像')->image();
            $show->field('campus_id','院区');
            $show->field('title_id','职称');
            $show->field('department_id','科室');
            $show->field('label','标签');
            $show->field('desc','描述');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new FourDoctor(), function (Form $form) {
            $form->display('id');
            $form->text('name');
            $form->image('avatar','头像');
            $form->select('campus_id','院区')->options(FourCampus::pluck('campus_name','id'));
            $form->select('title_id','职称')->options(FourAdminTitle::pluck('title','id'));
            $form->select('department_id','科室')->options(FourDepartment::pluck('name','id'));
            $form->checkbox('label_id','标签')->options(FourLabel::pluck('label_name','id'));
            $form->number('register_fee','挂号费');
            $form->number('check_fee','诊查费');
            $form->textarea('desc','描述');
            // 添加开关操作
            $form->switch('status', '状态');
            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
